package entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
@Entity
@Table(name="OrdenCompra")
public class OrdenCompraEntity extends DocumentoEntity implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4441257872695727042L;
	private int numero;
	@OneToOne(cascade=CascadeType.ALL)
	@JoinColumn
	private ProveedorEntity proveedor;
	private double total;
	private double iva;
	
	public ProveedorEntity getProveedor() {
		return proveedor;
	}
	public void setProveedor(ProveedorEntity proveedor) {
		this.proveedor = proveedor;
	}
	public double getTotal() {
		return total;
	}
	public void setTotal(double total) {
		this.total = total;
	}
	public double getIva() {
		return iva;
	}
	public void setIva(double iva) {
		this.iva = iva;
	}
	
	public int getNumero() {
		return numero;
	}
	public void setNumero(int numero) {
		this.numero = numero;
	}
	public void calcularImportes(){
		for(int i=0;i<items.size();i++){
			ItemEntity it=items.get(i);
			this.total=it.getPrecio()*it.getCantidad();
		}
		this.iva=this.total*0.21;
	}
	
	public OrdenCompraEntity(int numero, Date fecha,
			List<ItemEntity> items, int numero2,
			ProveedorEntity proveedor, double total, double iva) {
		super(numero, fecha, items);
		numero = numero2;
		this.proveedor = proveedor;
		this.total = total;
		this.iva = iva;
	}
	public OrdenCompraEntity(){
		
	}

}
